function ajaxDoc(id){
    var elem_search = document.getElementById(id);
    var key = elem_search.getAttribute("name");
    var value = elem_search.value;
    
    xmlhttp = new XMLHttpRequest();
    
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
            var text = xmlhttp.responseText;
            modifyTable(text);
        }
    }
    
    xmlhttp.open("POST", "select_do.jsp", true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    var send_text = key + "=" + value;
    xmlhttp.send(send_text);
}

function modifyTable(jsonText){
    var objs = JSON.parse(jsonText);
    
    var book_table = document.getElementById("select_book_table");
    // 表格行数
    // alert(book_table.rows.length);
    var len = book_table.rows.length;
    
    for (var i = 0; i < objs.length; i++) {
        var elem = objs[i];
        
        var row = book_table.insertRow(book_table.rows.length);
        var cell0 = row.insertCell(0);
        var cell1 = row.insertCell(1);
        var cell2 = row.insertCell(2);
        var cell3 = row.insertCell(3);
        var cell4 = row.insertCell(4);
        var cell5 = row.insertCell(5);
        var cell6 = row.insertCell(6);
        var cell7 = row.insertCell(7);
        decCell(cell0, elem.book_index, "book_index");
        decCell(cell1, elem.title, "title");
        decCell(cell2, elem.author, "author");
        decCell(cell3, elem.publisher, "publisher");
        decCell(cell4, elem.publish_time, "publish_time");
        decCell(cell5, elem.category, "category");
        decCell(cell6, elem.price, "price");
        
        var span01 = document.createElement("span");
        var button01 = document.createElement("button");
        button01.innerText = "编辑";
        button01.type = "button";
        decButton(button01, "button-small");
        span01.appendChild(button01);
        // span01.onclick = "editPanel(" + elem.id + ")";
        span01.onclick = function(){
            editPanel(elem.id);
        }
        cell7.appendChild(span01);
        
        var a01 = document.createElement("a");
        var button02 = document.createElement("button");
        button02.innerText = "删除";
        button02.type = "button";        
        decButton(button02, "button-small");
        a01.appendChild(button02);
        a01.href = "delete_do.jsp?id=" + elem.id;
        a01.style.marginLeft = "5px";
        cell7.appendChild(a01);
    }
    
    for (var i = 0; i < len - 1; i++) {
        var elem = book_table.rows[i];
        book_table.deleteRow(1);
    }
    
    function decButton(button, cla){
        button.classList.add(cla);
    }
    
    function decCell(cell, value, key){
        cell.innerHTML = value;
        cell.className = key;
    }
    
}